﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>AddSysUser</title>
    <link rel="stylesheet" type="text/css" href="../../Content/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../../Content/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="../../Content/themes/default/form.css" />
    <script type="text/javascript" language="javascript" src=' <%=Url.Content("~/Scripts/jquery-1.4.4.min.js") %>'></script>
    <script type="text/javascript" language="javascript" src='<%=Url.Content("~/Scripts/jquery.easyui.min.js") %>'></script>
    <script type="text/javascript" src='<%=Url.Content("~/Scripts/jquery.form.js") %>'></script>
    <script type="text/javascript" language="javascript" src=' <%=Url.Content("~/Scripts/jquery.validate.js") %>'></script>
    <script type="text/javascript" language="javascript">
        function resetpwd(t) {
            if (!confirm("您真的将密码重置为“000000”吗？"))
                return;
            var selt = $(t);
            var td = selt.parents("td");
            var tds = td.siblings("td[field=Id]");
            var id = tds.children("div").text();
            $.ajax({
                url: '../Admin/ResetPwd',
                type: 'Post',
                data: { id: id },
                timeout: 20000,
                error: function(data) {
                    alert("发生未知异常，删除失败，请您稍候再试！");
                },
                success: function(data) {
                    if (data == 1) {
                        alert("重置成功！密码为“00000”");
//                        $('#test').datagrid('reload');
                    } else {
                        alert(data);
                    }
                }
            });
        }
        function changeobj(t) {
            var selt = $(t);
            var td = selt.parents("td");
            var tds = td.siblings("td[field=Id]");
            var id = tds.children("div").text();         
            window.self.parent.addTab('修改用户信息', '../Admin/UpdateSysUser/' + id, 'icon-users');
        }
        function deleteobj(t) {
            if (!confirm("您真的要删除项吗？"))
                return;
            var selt = $(t);
            var td = selt.parents("td");
            var tds = td.siblings("td[field=Id]");
            var id = tds.children("div").text();
            $.ajax({
            url: '../Admin/DeleteSysUser',
                type: 'Post',
                data: { id: id },
                timeout: 20000,
                error: function(data) {
                    alert("发生未知异常，删除失败，请您稍候再试！");
                },
                success: function(data) {
                    if (data == 1) {
                        $('#test').datagrid('reload');
                    } else {
                        alert(data);
                    }
                }
            });
        }
        ///加载数据到datagrid
        function CreateDataGrid() {
            var result = $("#result");
            var w = result.parent("div").width() * 0.98;
            var lwidth = w/15;
            var rwidth = w/15;
            var test = $('#test');
            test.datagrid({
            title: '系统用户信息',
                iconCls: 'icon-save',
                width: w,
                height: 350,
                nowrap: false,
                striped: true,
                collapsible: true,
                url: '../Admin/GetSysUser',
                loadMsg: "正在加载数据......",
                columns: [[
			        { title: '系统用户信息', colspan:15 },
					{ field: 'opt', title: '操作', width: 150, align: 'center', rowspan: 1,
					    formatter: function(value, rec) {
					    return '<span style=" cursor: pointer;"> <a href="javascript:void(0)" onclick="resetpwd(this)">重置密码</a> <a href="javascript:void(0)"  onclick="changeobj(this)">修改</a><a  href="javascript:void(0)"  onclick="deleteobj(this)"> 删除</a></span>';
					    }
					}
				], [
					{ field: 'Id', title: '', width: 0 },
                    { field: 'PSUserName', title: '用户名', width:80, rowspan: 1 },
                    { field: 'PSTruename', title: '用户真名', width:80, rowspan: 1 },
                    { field: 'PSSex', title: '性别', width:32, rowspan: 1 },
                    { field: 'Role', title: '所属角色', width:80, rowspan: 1 },
                    { field: 'region', title: '用户地区', width:100, rowspan: 1 },
                    { field: 'PSRegTime', title: '注册时间', width:80, rowspan: 1 },
                    { field: 'PSEmail', title: '邮件', width:100, rowspan: 1 },
                    { field: 'PSMobilePhone1', title: '手机1', width:100, rowspan: 1 },
                    { field: 'PSMobilePhone2', title: '手机2', width:100, rowspan: 1 },
                    { field: 'PSTel1', title: '电话1', width:100, rowspan: 1 },
                    { field: 'PSTel2', title: '电话2', width:100, rowspan: 1 },
                    { field: 'PSTel3', title: '电话3', width: 100, rowspan: 1 },
                    { field: 'PSLoginTime', title: '登录时间', width:100, rowspan: 1 },
                    { field: 'PSState', title: '状态', width:32, rowspan: 1 } 
				]],
                pagination: true,
                rownumbers: false
            });
            test.datagrid('hideColumn', 'Id');
        }
        $(function() {
            CreateDataGrid();
            var userForm = $("#userForm");
            var tbs = userForm.children("table").children("tbody").children("tr").children("td");
            userForm.validate({
                rules: {
                    userName: {
                        required: true,
                        minlength: 2,
                        remote: {
                            url: "../Admin/VerifySysUserName",     //后台处理程序 
                            type: "post",               //数据发送方式 
                            dataType: "json"           //接受数据格式    
                        }
                    },
                    userPwd: {
                        required: true,
                        minlength: 6
                    },
                    repwd: {
                        equalTo: "#userPwd"
                },
                ddlrole: {
                     required: true
                    
                }
            }
        });
        //ajaxform 添加信息
        function ValidRequest() {
            return userForm.validate().form(); // 返回是否验证成功            
        }
        function showResponse(responseText, statusText) {
            if (responseText == "1") {
                userForm.resetForm();
                CreateDataGrid();
            } else {
                alert(responseText);
            }
        }
        var options = {
            url: '../Admin/InsertUser',
            beforeSubmit: ValidRequest,
            success: showResponse
        }
        userForm.ajaxForm(options);
    });
    </script>
</head>
<body>
   <div id="main_body">
        <form id="userForm" runat="server" >
        <table class="formTable">
            <thead>
                <tr>
                    <td class="headlf">
                        添加系统用户
                    </td>
                    <td class="headrh">
                        <a class="ce" href="javascript:void(0)" onclick="mytoggle(this)">收起</a>
                    </td>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td class="label">
                        用户名：
                    </td>
                    <td>
                        <input type="text" id="userName" name="userName" />
                    </td>
                </tr>
                <tr>
                    <td class="label">
                        密 码：
                    </td>
                    <td>
                        <input type="password" id="userPwd" name="userPwd" />
                    </td>
                </tr>
                <tr>
                    <td class="label">
                       确认密码：
                    </td>
                    <td>
                        <input type="password" id="repwd" name="repwd" />
                    </td>
                </tr>
                  <tr>
                    <td class="label">
                       用户角色：
                    </td>
                    <td>
                         <%= Html.DropDownList("ddlrole")%>      
                    </td>
                </tr>
                <tr>
                    <td class="label" style="text-align: left; padding-left: 250px;" colspan="2">
                        <input type="submit" id="addUser" value="添加" />
                    </td>
                </tr>
            </tbody>
        </table>
        </form>
        <div id="result">
            <table id="test">
            </table>
        </div>
    </div>
</body>
</html>
